#include <Arduino.h>
#include <EEPROM.h>
#include "LEDDayDriver.h"
DayParams day = {0, 255, 100/*daystart*/,18000 /*daylengthtime*/, 0 /*timeAdj*/};
PWMParams pwmpar = PWMParams(13/*pin*/, 2000/*pulseLength*/,0,0);
TimerQueue microtimer;
TimerQueue millitimer;
LEDDayDriver leds[] = 
{
  LEDDayDriver(millitimer, microtimer, day, PWMParams(2/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(3/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(4/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(5/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(6/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(7/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(8/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(9/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(10/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(11/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(12/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(13/*pin*/, 2000/*pulseLength*/,0,0)),
  LEDDayDriver(millitimer, microtimer, day, PWMParams(14/*pin*/, 2000/*pulseLength*/,0,0)),//A0
  LEDDayDriver(millitimer, microtimer, day, PWMParams(15/*pin*/, 2000/*pulseLength*/,0,0)),//A1
  LEDDayDriver(millitimer, microtimer, day, PWMParams(16/*pin*/, 2000/*pulseLength*/,0,0))//A2
};
void configureDay()
{
    int pin = Serial.parseInt();
    if(pin < 17 && pin > 1 )
    {
          DayParams param = leds[pin-2].getDayConfig();
          param.daystarttime = Serial.parseInt();
          param.daylengthtime = Serial.parseInt();
          param.min = Serial.parseInt();
          param.max = Serial.parseInt();
          leds[pin-2].setDayConfig(param);
//          unsigned char startAddr = (sizeof(DayParams)+sizeof(PwmParams))*(pin-2);
//          param.writeToEeprom(startAddr);
    }

}
void configurePwm()
{}
void setup() {
  Serial.begin(9600);                 // create the serial connection at 9600bit/s baudrate
} 
void loop()
{

  while(Serial.available() > 0)
  {
    char data = Serial.read();
    switch(data)
    {
        case 'd':
        {
            configureDay();
            break;
        }
        case 'p':
        {
            configurePwm();
            break;
        }
    }


  }
 millitimer.periodicTimerTick(millis()); 
 microtimer.periodicTimerTick(micros()); 

}

